import { Application } from "express";

export default function productionMiddleware(app: Application) {
  // 防盗链
  app.use((req, res, next) => {
    const referer = req.get("Referer");
    if (!referer) return next();
    const url = new URL(referer);
    const { hostname } = url;
    if (hostname !== process.env.SERVER_ADDRESS) {
      return res.status(404).send("Not Found");
    }
    next();
  });
}
